// 弹窗-layer二次封装
define([
  "layer"
], function(layer) {
  var layerCopy = {};

  var defaultOps = {
    iconPath: "../../lib/skin/jigou/",    // 自定义icon路径
    time: 2000                      // 若提示自动关闭时间
  };

  layerCopy.open = function(ops){
    var ags = [].slice.call(arguments);

    return layer.open.apply(this, ags);
  };

  layerCopy.alert = function(){
    var ags = [].slice.call(arguments);
    
    return layer.alert.apply(this, ags);
  };

  layerCopy.confirm = function(){
    var ags = [].slice.call(arguments);
    
    return layer.confirm.apply(this, ags);
  };

  layerCopy.msg = function(){
    var ags = [].slice.call(arguments);
    
    return layer.msg.apply(this, ags);
  };

  layerCopy.load = function(){
    var ags = [].slice.call(arguments);
    
    return layer.load.apply(this, ags);
  };

  layerCopy.tips = function(){
    var ags = [].slice.call(arguments);
    
    return layer.tips.apply(this, ags);
  };

  layerCopy.close = function(){
    var ags = [].slice.call(arguments);
    
    return layer.close.apply(this, ags);
  };

  layerCopy.closeAll = function(){
    var ags = [].slice.call(arguments);
    
    return layer.closeAll.apply(this, ags);
  };

  layerCopy.title = function(){
    var ags = [].slice.call(arguments);
    
    return layer.title.apply(this, ags);
  };

  layerCopy.style = function(){
    var ags = [].slice.call(arguments);
    
    return layer.style.apply(this, ags);
  };

  /**
   * @Author    李鹏
   * @email     542416615@qq.com
   * @DateTime  2017-07-19
   * @copyright [layer成功强提示]
   * @param     {[string]}       msg [提示文字]
   * @param     {Function}       cb  [关闭回调]
   * @return    {[number]}           [layer索引]
   */
  layerCopy.boxSuccess = function(msg, cb){
    var _msg = "操作成功";

    if (msg) {
      _msg = msg;
    }
    
    return layer.open({
      type: 1,
      area: "470px",
      title: "提示",
      btn: [],
      end: function(){ 
        cb && cb();
      },
      content: `<div class="openBox boxSuccess">
        <div class="il">
          <img src="${defaultOps.iconPath}/layerIcon4.png" alt="" />
        </div>
        <span>${_msg}</span>
      </div>`
    });
  };

  /**
   * @Author    李鹏
   * @email     542416615@qq.com
   * @DateTime  2017-07-19
   * @copyright [layer失败强提示]
   * @param     {[string]}       msg [提示文字]
   * @param     {Function}       cb  [关闭回调]
   * @return    {[number]}           [layer索引]
   */
  layerCopy.boxError = function(msg, cb){
    var _msg = "操作失败";

    if (msg) {
      _msg = msg;
    }

    return layer.open({
      type: 1,
      area: "470px",
      title: "提示",
      btn: [],
      end: function(){ 
        cb && cb();
      },
      content: `<div class="openBox boxError">
        <div class="il">
          <img src="${defaultOps.iconPath}/layerIcon3.png" alt="" />
        </div>
        <span>${_msg}</span>
      </div>`
    });
  };
  
  /**
   * @Author    李鹏
   * @email     542416615@qq.com
   * @DateTime  2017-07-19
   * @copyright [layer成功弱提示]
   * @return    {[number]}         [layer index]
   */
  layerCopy.msgSuccess = function(cb){
    var index = layer.msg('操作成功', {
      icon: 1,
      time: defaultOps.time //关闭（如果不配置，默认是3秒）
    }, function(){
      cb && cb();
    })

    return index;
  };
  
  /**
   * @Author    李鹏
   * @email     542416615@qq.com
   * @DateTime  2017-07-19
   * @copyright [layer失败弱提示]
   * @return    {[number]}         [layer index]
   */
  layerCopy.msgError = function(msg, cb){
    var index = layer.msg(msg || '操作失败', {
      icon: 2,
      time: defaultOps.time //关闭（如果不配置，默认是3秒）
    }, function(){
      cb && cb();
    })

    layer.style(index, {
      background: "rgba(0,0,0,.75)"
    });

    return index;
  };

  return layerCopy;
});